home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / fstat.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  3.9 KB  |  139 lines

  1. #
  2. # fstat.test
  3. #
  4. # Tests for the fstat command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: fstat.test,v 2.0 1992/10/16 04:49:50 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. unlink -nocomplain gorp.file
  22. set gorpFH [open gorp.file w]
  23. puts $gorpFH "Test string"
  24. close $gorpFH
  25. chmod 0765 gorp.file
  26.  
  27. set gorpFH [open gorp.file r+]
  28.  
  29. Test fstat-1.1 {array return} {
  30.     catch {unset stat}
  31.     fstat $gorpFH stat stat
  32.     lsort [array names stat]
  33. } 0 {atime ctime dev gid ino mode mtime nlink size tty type uid}
  34.  
  35. Test fstat-1.2 {array return} {
  36.     catch {unset stat}
  37.     fstat $gorpFH stat stat
  38.     list $stat(nlink) $stat(size) [expr $stat(mode)&0777] $stat(type) \
  39.          $stat(tty)
  40. } 0 {1 12 501 file 0}
  41.  
  42. Test fstat-1.3 {array return} {
  43.     catch {unset stat}
  44.     fstat $gorpFH stat stat
  45.     list [expr {[file mtime gorp.file] == $stat(mtime)}] \
  46.         [expr {[file atime gorp.file] == $stat(atime)}] $stat(size)
  47. } 0 {1 1 12}
  48.  
  49. Test fstat-2.1 {keyed list returns} {
  50.     catch {unset stat}
  51.     set stat [fstat $gorpFH]
  52.     lsort [keylkeys stat]
  53. } 0 {atime ctime dev gid ino mode mtime nlink size tty type uid}
  54.  
  55. Test fstat-2.2 {keyed list returns} {
  56.     set stat [fstat $gorpFH]
  57.     list [keylget stat nlink] [keylget stat size] \
  58.          [expr [keylget stat mode ]&0777] [keylget stat type]
  59. } 0 {1 12 501 file}
  60.  
  61. Test fstat-2.3 {keyed list returns} {
  62.     set stat [fstat $gorpFH]
  63.     list [expr {[file mtime gorp.file] == [keylget stat mtime]}] \
  64.         [expr {[file atime gorp.file] == [keylget stat atime]}] \
  65.             [keylget stat size]
  66. } 0 {1 1 12}
  67.  
  68.  
  69. Test fstat-3.1 {individual item returns} {
  70.     set old [fstat $gorpFH mtime]
  71.     exec sleep 2
  72.     puts $gorpFH "More text"
  73.     flush $gorpFH
  74.     set new [fstat $gorpFH mtime]
  75.     expr {($new > $old) && ($new <= ($old+5))}
  76. } 0 {1}
  77.  
  78. Test fstat-3.2 {individual item returns} {
  79.     set oldsize [fstat $gorpFH size]
  80.     puts $gorpFH "More text"
  81.     flush $gorpFH
  82.     expr {[fstat $gorpFH size] - $oldsize}
  83. } 0 {8}
  84.  
  85. Test fstat-4.1 {type return} {
  86.     set fh [open .]
  87.     set type [fstat $fh type]
  88.     close $fh
  89.     set type
  90. } 0 directory
  91.  
  92. Test fstat-4.2 {type return} {
  93.     fstat $gorpFH type
  94. } 0 file
  95.  
  96. #
  97. # Check to see that the values that are returned are at least numeric where
  98. # expected
  99. #
  100. Test fstat-4.3 {type return} {
  101.     set dataList {}
  102.     foreach type {dev ino mode nlink uid gid size atime mtime ctime tty
  103.                   type} {
  104.         set data [fstat $gorpFH $type]
  105.         if [string match "-*" $data] {
  106.             set data [csubstr $data 1 end]
  107.         }
  108.         lappend dataList [ctype digit $data]
  109.     }
  110.     set dataList
  111. } 0 {1 1 1 1 1 1 1 1 1 1 1 0}
  112.  
  113.  
  114. Test fstat-5.1 {error handling} {
  115.     fstat
  116. } 1 {wrong # args: fstat handle [item]|[stat arrayVar]}
  117.  
  118. Test fstat-5.2 {error handling} {
  119.     fstat foo
  120. } 1 {bad file identifier "foo"}
  121.  
  122. Test fstat-5.3 {error handling} {
  123.     fstat $gorpFH foo
  124. } 1 {Got "foo", expected one of "atime", "ctime", "dev", "gid", "ino", "mode", "mtime", "nlink", "size", "tty", "type", "uid"}
  125.  
  126. Test fstat-5.4 {error handling} {
  127.     catch {unset foo}
  128.     fstat $gorpFH foo foo
  129. } 1 {expected item name of "stat" when using array name}
  130.  
  131. Test fstat-5.5 {error handling} {
  132.     catch {unset foo}
  133.     fstat $gorpFH stat foo baz
  134. } 1 {wrong # args: fstat handle [item]|[stat arrayVar]}
  135.  
  136.  
  137. catch {close $gorpFH}
  138. unlink -nocomplain gorp.file
  139.